@extends('admin.layouts.ui')
@section('title','后台管理欢迎页面')
@section('content')
    <div class=" clearfix" id="advertising">
        <div class="Ads_list" style="margin-left: 0;">

            <!-- 模态框（Modal） -->
            <div class="modal  fade bs-example-modal-center" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" style="display: none;" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">添加客户端首页轮播图片</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        </div>
                        <div class="modal-body">
                            <div class="card">
                                <div class="card-body">
                                    {!! Form::open(['route' => 'advertising.store', 'method' => 'post','id'=>'form']) !!}
                                        <div class="form-row">

                                            <div class="form-group col-lg-6">
                                                <label for="firstname">图片标题</label>
                                                <input type="text" name="title" class="form-control" id="firstname">
                                            </div>
                                            <div class="form-group col-lg-6">
                                                <label for="lastname">排序</label>
                                                <input type="text" class="form-control" id="sort" name="sort">
                                            </div>
                                            <div class="form-check col-md-12 m-b-20">
                                                <div class="custom-control custom-radio radio custom-control-inline">
                                                    <input type="radio" class="custom-control-input" name="is_show" value="0" id="is_show" checked="checked">
                                                    <label class="custom-control-label" for="is_show">显示</label>
                                                </div>
                                                <div class="custom-control custom-radio radio custom-control-inline">
                                                    <input type="radio" class="custom-control-input" name="is_show" value="1" id="gender">
                                                    <label class="custom-control-label" for="gender">隐藏</label>
                                                </div>
                                            </div>
                                            <div class="form-group col-lg-12">
                                                <label for="username">图片上传</label>
                                                <div class="card">
                                                    <div class="card-body">
                                                        <h3 class="card-title">Special title treatment</h3>
                                                        <blockquote class="card-bodyquote">
                                                            <div id="cupload-create" style="padding: 10px;"></div>
                                                        </blockquote>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group col-lg-12 text-righ">
                                                <button type="submit" class="btn btn-common">Submit</button>
                                            </div>
                                        </div>
                                    {!! Form::close() !!}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card">
                <div class="card-header border-bottom">
                    <button type="button" class="btn btn-outline-secondary" data-toggle="modal" data-target=".bs-example-modal-center">添加客户端轮播图</button>
                </div>
                <div class="card-body">
                    <p class="text-muted m-b-20 box-content">
                        客户端轮播图列表展示
                    </p>
                    <div class="table-responsive">
                        <table class="table mb-0">
                            <thead class="thead-default">
                            <tr>
                                <th>ID</th>
                                <th>排序</th>
                                <th>图片</th>
                                <th>创建时间</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @each('admin.carousel._table_tr',$carousels,'carousel')
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div style="margin-left: 37em">{{ $carousels->links() }}</div>
        </div>

    </div>

@stop
@section('js')
    <script src="{{ asset('admin/Widget/cupload/cupload.js') }}"></script>
    <script type="text/javascript">
        var cuploadCreate = new Cupload({
            ele: '#cupload-create',
            num: 1,
        });
        $('#form').Validform({
            tiptype : 4,
            ajaxPost : true,
            beforeCheck:function(curform){
                console.log(curform);
                //在表单提交执行验证之前执行的函数，curform参数是当前表单对象。
                //这里明确return false的话将不会继续执行验证操作;
            },
            callback : function (res) {
                console.log(res);
                if(res.status == 422) {
                    var json=JSON.parse(res.responseText);
                    $.each(json.errors, function(idx, obj) {
                        layer.msg(obj[0], {icon: 5});
                        return false;
                    });
                } else if(res.status== 200) {
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        $(".bs-example-modal-center").modal('hide');
                        location.href = '{{ route('advertising.index') }}'
                    });

                }
            },
        });

        function del(obj,id){
            layer.confirm('确认要删除吗？',function(index){
                $.ajaxSetup({
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
                });
                $.ajax({
                    type : 'delete',
                    url : "{{ url('admin/advertising') }}" + '/'+ id,
                    datatype : 'json',
                    beforeSend : function () {
                        index = layer.load(1, {shade: [0.6, '#393D49']});
                    },
                    success: function(response, status, xhr) {
                        switch (response.status) {
                            case 200 :
                                layer.close(index);
                                layer.msg(response.msg, {icon: 1,shade: [0.6, '#393D49'],time:2000});
                                setTimeout(function () {
                                    location.href = '{{ route('advertising.index') }}';
                                },1000);
                                break;
                            case '422' :
                                layer.close(index);
                                layer.msg(response.msg, {icon: 5,shade: [0.6, '#393D49'],time:2000});
                                break;
                        }
                    }
                });

            });
        }
    </script>
@stop

